Memory is a critical system resource that determines database performance and stability to a large extent. In this specification, the term “memory,” unless modified, refers to random access memory. In the absence of enough memory, queries can slow down because of spilling or simply error out, resulting in undesirable behavior. As memory is unlimited, proper memory management is the key to ensure fair and acceptable usage, and the best possible user experience.
In a massively parallel processing (MPP) database, the following high level steps describe query processing:                1. User submits a query.        2. Parser parses the query.        3. Planner plans the query and produces a query plan tree, consisting of different processes; processes may occur multiple times in the tree.        4. A memory quota process assigns each operator a certain memory quota that defines the maximum memory the operator can use, to limit its runtime memory allocation.        5. The plan is dispatched to multiple worker nodes to execute in a distributed manner.        6. Each worker node receives its copy of the plan tree which indicates the memory quotas assigned to the processes.        7. A query execution engine executes the plan.        8. A result is returned back to the user, through the server.        
Throughout this process, memory is allocated by multiple queries. To ensure fair usage and proper utilization of memory as well as to ensure system stability, the system must do the following:                1. Measure memory usage of each query.        2. Check to see if the memory usage is within the quota.        3. Enforce the memory quota for different queries.        
Every major database has a memory manager to efficiently allocate and free memory. Moreover, major databases have algorithms to assign memory quota to SQL (structured query language) statements during the planning of a query. During execution, memory managers commonly use memory regions to allocate memory to SQL operators, mostly for efficiency and for tracking allocations.